home *** CD-ROM | disk | FTP | other *** search
- /*
- File: usbprint.c
-
- Contains: usb printer class device communication
- (installed in UnitTable)
-
- */
- #include "PrinterClassDriver.h"
-
- #ifndef __DEVICES__
- #include <devices.h>
- #endif
-
- #ifndef __FILES__
- #include <files.h>
- #endif
-
- #define kMaskLowByte 0x0FF
-
- extern pascal OSErr DRVRDone( OSErr err, DCtlPtr ctl, IOParamPtr pb );
- static void AbortActive( CntrlParam *pb, DCtlPtr clt );
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: GetPrinterStruct
-
- Input Parameters: IOParamPtr i/o parameter block
-
- Output Parameters:
- usbPrinterPBStruct * pointer to the device
-
- Description:
- Given a device control block, map it to a usb device's data structure
-
- Change History:
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- static struct usbPrinterPBStruct *
- GetPrinterStruct( DCtlPtr ctl )
- {
- return (struct usbPrinterPBStruct *) ctl->dCtlStorage;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: Read
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 11 Jun 1998, oja: return pb->ioResult, not usbprint->in.usbStatus
- 4 Apr 1998, oja: Fix handshaking: do not set pb->ioResult
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- static OSErr
- Read (IOParamPtr pb, DCtlPtr ctl)
- {
- struct usbPrinterPBStruct *usbprint = GetPrinterStruct( ctl );
-
- //
- // if we have a unidirectional interface
- // report a read error
- // (only status supported by unidirectional is Centronics compatible)
- //
- pb->ioResult = paramErr; // assume bad
-
- if ( usbprint->interface->interfaceProtocol == kUSBPrintClassProtocolUnidirectional )
- pb->ioResult = readErr;
- else if ( usbprint != NULL )
- (*usbprint->qread)( pb, ctl, usbprint ); // map the read param block into the usb param block
-
- return pb->ioResult;
-
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: Write
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 11 Jun 1998, oja: return pb->ioResult, not usbprint->out.usbStatus
- 4 Apr 1998, oja: Fix handshaking: do not set pb->ioResult
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- static OSErr
- Write (IOParamPtr pb, DCtlPtr ctl)
- {
- struct usbPrinterPBStruct *usbprint = GetPrinterStruct( ctl );
-
- pb->ioResult = paramErr; // assume bad
-
- if ( usbprint != NULL )
- (*usbprint->qwrite)( pb, ctl, usbprint ); // map the write param block into the usb param block
-
- return pb->ioResult;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: AbortActive
-
- Input Parameters:
- pb
- ctl
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 4 Aug 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- static void
- AbortActive( CntrlParam *pb, DCtlPtr ctl )
- {
- // we need to wait here until the transaction is complete
- struct usbPrinterPBStruct *usbprint = GetPrinterStruct( ctl );
- struct USBPB *pActiveUSBIO;
- IOParamPtr pActiveIO;
-
- if ( usbprint != NULL )
- {
- if ( pb->ioCRefNum == usbprint->outRefNum )
- {
- pActiveUSBIO = &usbprint->out;
- pActiveIO = usbprint->writeDrvr.pb;
- }
- else
- {
- pActiveUSBIO = &usbprint->in;
- pActiveIO = usbprint->readDrvr.pb;
- }
- if ( pActiveUSBIO->usbCompletion != NULL )
- {
- (*usbprint->qabort)( pb->ioCRefNum, usbprint ); // cancel outstanding transactions
- //
- // synchronize data toggle
- // USB addendum, the endpoints of the pipe may be out of sync
- // a soft reset in the printer class should restore the data toggle
- //
- pb->csCode = kDrvrSoftReset;
- (*usbprint->qstatus)( pb, ctl, usbprint );
-
- }
- }
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: DRVROpen
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- pascal OSErr
- DRVROpen(CntrlParam *pb, DCtlPtr dce)
- {
- return noErr;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: DRVRClose
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- pascal OSErr
- DRVRClose(CntrlParam *pb, DCtlPtr ctl)
- {
- return noErr;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: DRVRStatus
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 30 Jun 1998, oja: pass through messages for kDrvrCentronicsStatus,
- kDrvr1284IdString,kDrvrSoftReset
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- pascal OSErr
- DRVRStatus(CntrlParam *pb, DCtlPtr ctl)
- {
- OSErr err;
- struct usbPrinterPBStruct *usbprint = GetPrinterStruct( ctl );
-
- switch ( pb->csCode )
- {
- case kDrvrCentronicsStatus: // USB device: centronics status
- case kDrvr1284IdString: // USB device: 1284 capability string
- case kDrvrSoftReset: // USB device: soft reset
- if ( usbprint != NULL )
- (*usbprint->qstatus)( pb, ctl, usbprint ); // map the status param block into the usb param block
- err = pb->ioResult;
- break;
- case kDrvrNumDevices:
- err = noErr;
- break;
- case 1:
- case 2: // deprecated
- default:
- err = paramErr;
- break;
- }
- return err;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: DRVRControl
-
- Input Parameters:
- csCode csParam
- ------ -------
- kDrvrPrivateSetStorage pointer to the USB device class storage
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 12 Jun 1998, oja: default to noErr (was uninitialized with killCode)
- 11 Jun 1998, oja: abort active usb transactions
- 4 Apr 1998, oja Removed unused code for private done i/o
- pass error code to DrvrDone
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- pascal OSErr
- DRVRControl(CntrlParam *pb, DCtlPtr ctl)
- {
- OSErr err = noErr;
- struct usbPrinterPBStruct *usbprint = GetPrinterStruct( ctl );
-
- switch ( pb->csCode )
- {
- case killCode:
- //
- // killIO is always handled as an immediate mode transaction
- //
- AbortActive( pb, ctl );
- break;
- case kDrvrPrivateSetStorage:
- //
- // reference the class driver's private storage
- // it's not a handle, but devices.h thinks it should be
- //
- ctl->dCtlStorage = (Handle) *((Ptr *) &pb->csParam[0] );
- break;
- default:
- err = paramErr;
- break;
- }
- return err;
- }
-
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: DRVRPrime
-
- Input Parameters:
-
- Output Parameters:
- <none>
-
- Description:
-
- Change History:
- 28 Feb 1998, oja: Original version.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- pascal OSErr
- DRVRPrime(CntrlParam *pb, DCtlPtr ctl)
- {
- OSErr err = paramErr;
- //
- // switch on the low order byte to dispatch reads and writes
- //
- if ( (pb->ioTrap & kMaskLowByte) == aRdCmd )
- err = Read( (IOParamPtr) pb, ctl );
- else if ( (pb->ioTrap & kMaskLowByte) == aWrCmd )
- err = Write( (IOParamPtr) pb, ctl );
-
- //
- // get the ioResult in case the completion routine has already executed
- //
- if ( err == noErr )
- err = pb->ioResult;
-
- return err;
- }
-
- // eof
-